package com.dxy.df.modules.service.impl;

import com.dxy.df.constants.ConstStrings;
import com.dxy.df.core.shiro.ShiroUtils;
import com.dxy.df.modules.bean.entity.UserPublishGiveRiceEntity;
import com.dxy.df.modules.bean.put.UserPublishGiveRicePut;
import com.dxy.df.modules.bean.query.UserPublishGiveRiceQuery;
import com.dxy.df.modules.bean.vo.UserPublishGiveRiceVo;
import com.dxy.df.modules.dao.UserPublishGiveRiceMapper;
import com.dxy.df.modules.service.UserPublishGiveRiceService;
import com.dxy.df.utils.UcBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


/**
 * @author biz@dxy.cn
 * @describe 用户出饭信息发布
 * @date 2019-10-25 15:36:06
 */
@Service
public class UserPublishGiveRiceServiceImpl implements UserPublishGiveRiceService {
    @Autowired
    private UserPublishGiveRiceMapper userPublishGiveRiceMapper;

    @Override
    public UserPublishGiveRiceEntity queryObject(UserPublishGiveRiceQuery query) {
        return userPublishGiveRiceMapper.queryObject(query);
    }

    @Override
    public List<UserPublishGiveRiceVo> queryList(UserPublishGiveRiceQuery query) {
        return userPublishGiveRiceMapper.queryList(query);
    }

    @Override
    public int queryTotal(UserPublishGiveRiceQuery query) {
        return userPublishGiveRiceMapper.queryTotal(query);
    }

    @Override
    public UserPublishGiveRiceEntity save(UserPublishGiveRicePut put) {
        UserPublishGiveRiceEntity entity = UcBeanUtils.copyPropertiesForDDL(put,
                UserPublishGiveRiceEntity.class, ConstStrings.ADD);
        entity.setUserId(ShiroUtils.getUserAccount());
        userPublishGiveRiceMapper.save(entity);
        return entity;
    }

    @Override
    public void update(UserPublishGiveRicePut put) {
        UserPublishGiveRiceEntity entity = UcBeanUtils.copyPropertiesForDDL(put, UserPublishGiveRiceEntity.class, "");
        entity.setUserId(ShiroUtils.getUserAccount());
        userPublishGiveRiceMapper.update(entity);
    }

    @Override
    public void delete(Integer id) {
        userPublishGiveRiceMapper.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        return userPublishGiveRiceMapper.deleteBatch(ids);
    }

    @Override
    public UserPublishGiveRiceVo querySuitInfo(String conditions) {
        if(StringUtils.isEmpty(conditions)){
            return null;
        }
        String[] conditionArray = conditions.split(",");
        return userPublishGiveRiceMapper.querySuitInfo(conditionArray);
    }
}
